package dom4j;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class Dom4jTest {
	/** 根元素标签 **/
	private static final String ROOT_ELEMENT="rootElement";
	/** 子元素标签 **/
	private static final String PERSON_ELEMENT="personElement";
	/**
	 * @param args
	 * @throws IllegalAccessException 
	 * @throws IllegalArgumentException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, IOException {
		//创建document对象
		Document document=DocumentHelper.createDocument();
		//创建XML文档的根对象
		Element projectElem=document.addElement(ROOT_ELEMENT);
		
		Element personLabel=null;
		List<Person> personList=getPersonList();
		for(Person person:personList){
			personLabel=projectElem.addElement(PERSON_ELEMENT);
			Dom4jUtil.produceObjXML(person, personLabel, new String[]{"label1","label2","label3","label4"}, 
					new String[]{"label1","label2","label3","label4"});
		}	
		Dom4jUtil.wirteXml("C:/test.xml", document);
	}

	private static List<Person> getPersonList(){
		List<Person> personList=new ArrayList<Person>();
		Person person1=new Person();
		person1.setLabel1("P1labe1Content");
		person1.setLabel2("P1labe2Content");
		person1.setLabel3("P1labe3Content");
		person1.setLabel4("P1labe4Content");
		personList.add(person1);
		Person person2=new Person();
		person2.setLabel1("P2labe1Content");
		person2.setLabel2("P2labe2Content");
		person2.setLabel3("P2labe3Content");
		person2.setLabel4("P2labe4Content");
		personList.add(person2);
		
		return personList;
	}
}
